import {createRouter, createWebHashHistory} from "vue-router";

import LoginView from "@/views/login/LoginView.vue";
import PortalView from "@/views/PortalView.vue";
import CodeGeneratorView from "@/views/codeGenerator/CodeGeneratorView.vue";

const routes = [
    {
        path: '/',
        redirect: '/portal',
    },
    {
        path: '/login',
        component: LoginView,
        meta: {
            title: '登录',
        }
    },
    {
        path: '/portal',
        component: PortalView,
        redirect: '/codeGenerator',
        meta: {
            title: '首页',
        },
        children: [
            {
                path: '/codeGenerator',
                component: CodeGeneratorView,
                meta: {
                    title: '代码生成器',
                }
            },
        ]
    },
]

const router = createRouter({
    history: createWebHashHistory(),
    routes,
})


router.beforeEach((to, from, next) => {
    console.log('to:', to.path, '  to:', to)

    // 设置浏览器标签页标题
    document.title = to.meta.title ? to.meta.title : '管理系统'

    next()
})

router.afterEach((to, from) => {

})

export default router
